package com.ruoyi.project.business.socialsecurity.service.impl;

import com.ruoyi.common.enums.SocialSecurityType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.project.business.socialsecurity.entity.SysSocialSecurity;
import com.ruoyi.project.business.socialsecurity.mapper.SysSocialSecurityMapper;
import com.ruoyi.project.business.socialsecurity.request.AddSysSocialSecurityRequest;
import com.ruoyi.project.business.socialsecurity.request.ListSysSocialSecurityRequest;
import com.ruoyi.project.business.socialsecurity.response.SysSocialSecurityResponse;
import com.ruoyi.project.business.socialsecurity.service.ISysSocialSecurityService;
import com.ruoyi.project.business.utils.BusinessUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 平台级每年社保基数维护Service业务层处理
 * 
 * @author ${author}
 * @date 2024-03-19
 */
@Service
public class SysSocialSecurityServiceImpl implements ISysSocialSecurityService {
    @Autowired
    private SysSocialSecurityMapper sysSocialSecurityMapper;

    /**
     * 查询平台级每年社保基数维护
     * 
     * @return 平台级每年社保基数维护
     */
    @Override
    public SysSocialSecurity selectSysSocialSecurityById(Long id) {
        return sysSocialSecurityMapper.selectSysSocialSecurityById(id);
    }

    /**
     * 查询平台级每年社保基数维护列表
     * 
     * @return 平台级每年社保基数维护
     */
    @Override
    public List<SysSocialSecurityResponse> selectSysSocialSecurityList(ListSysSocialSecurityRequest request) {
        SysSocialSecurity param = BeanUtils.copy(request, SysSocialSecurity.class);
        Date yearMonth = request.getYearMonth();
        int year = DateUtils.year(yearMonth);

        param.setYear(year);
        List<SysSocialSecurity> entitis = sysSocialSecurityMapper.selectSysSocialSecurityList(param);
        List<SysSocialSecurityResponse> resList = BeanUtils.copyList(entitis, SysSocialSecurityResponse.class);
        resList.forEach(res -> {
            res.setTypeName(SocialSecurityType.getEnumByCode(res.getType()).getDesc());
        });

        BusinessUtil.fillListNames(resList, null);

        return resList;
    }

    /**
     * 新增平台级每年社保基数维护
     * 
     * @return 结果
     */
    @Override
    public int insertSysSocialSecurity(AddSysSocialSecurityRequest request, Long operatorId) {
        SysSocialSecurity entity = BeanUtils.copy(request, SysSocialSecurity.class);
        Date yearMonth = request.getYearMonth();
        int year = DateUtils.year(yearMonth);
        entity.setYear(year);
        entity.setCreateTime(DateUtils.getNowDate());
        return sysSocialSecurityMapper.insertSysSocialSecurity(entity);
    }

    /**
     * 修改平台级每年社保基数维护
     * 
     * @return 结果
     */
    @Override
    public int updateSysSocialSecurity(SysSocialSecurity entity, Long operatorId) {
        return sysSocialSecurityMapper.updateSysSocialSecurity(entity);
    }

    /**
     * 批量删除平台级每年社保基数维护
     * 
     * @return 结果
     */
    @Override
    public int deleteSysSocialSecurityByIds(Long[] ids, Long operatorId) {
        return sysSocialSecurityMapper.deleteSysSocialSecurityByIds(ids);
    }

    /**
     * 删除平台级每年社保基数维护信息
     * 
     * @return 结果
     */
    @Override
    public int deleteSysSocialSecurityById(Long id, Long operatorId) {
        return sysSocialSecurityMapper.deleteSysSocialSecurityById(id);
    }

}
